#include "xpmio.h"
#include "lines.h"
#include <math.h>

void drawLine(float *x, float *y, float len, float theta, double** img) {

	int i;
	float x2 = *x + cos(theta)*len;
	float y2 = *y + sin(theta)*len;
	float dx = (x2-(*x))/len;
	float dy = (y2-(*y))/len;

	//printf("(%d,%d) -> (%f,%f) by (%f,%f)\n", (int)(*x), (int)(*y), x2, y2, dx, dy);
	img[(int)*x][(int)*y] = 1;
	for(i = 0; i < len; i++) {
		*x += dx;
		*y += dy;
		//printf("%d %d = 1\n", (int)*x, (int)*y);
		img[(int)*x][(int)*y] = 1;
	}

	//*x = (int)x2;
	//*y = (int)y2;
}

void movePoint(float *x, float *y, float len, float theta) {

	*x = (int)(*x + cos(theta)*len);
	*y = (int)(*y + sin(theta)*len);
}
/*
main(int argc, char** argv) {

	double** img;
	int i,j;
	float x = 0, y = 0;

	img = malloc(sizeof(double*)*64);

	for(i = 0; i < 64; i++) {
		img[i] = malloc(sizeof(double)*64);
		for(j = 0; j < 64; j++) {
			img[i][j] = 0;
		}
	}

	drawLine(&x, &y, 10, PI/2.0, img);
	movePoint(&x, &y, 4, PI/2.0);
	drawLine(&x, &y, 10, PI, img);
	writeXPM(img, 64, 64, "test.xpm");
}
*/
